#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,cnt,ans;
int a[N],c[N];
bool color[N];
void work(){
    cnt=0;
    for(int i=2;i<=n;i++)
        for(int j=i-1;j>=1;j--)
            if(color[i]==color[j]){
                if(a[i]==a[j]) c[i]=a[i];
                break;
            }
    for(int i=1;i<=n;i++)
        cnt+=c[i];
}
void dfs(int dep,bool x){
    if(dep>n){
        work();
        ans=max(ans,cnt);    
        memset(c,0,sizeof(c));
        return;
    }
    color[dep]=x;
    dfs(dep+1,x);
    dfs(dep+1,x^1);
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    memset(c,0,sizeof(c));
    memset(color,0,sizeof(color));
    ans=0;
    dfs(1,0);
    cout<<ans<<"\n";
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T;
    cin>>T;
    while(T--) solve();
    return 0;
}